<template>
	<view>
		<view v-if="isOnline">
			<view class="msinput">
				{{keys[key]}}：<input focus v-model="val" value="" />
			</view>
			<view class="submit" @click="clickAset">确认</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		components: {
			
		},
		computed: {
			isOnline() {
				let online = this.$store.getters['online/getOnline'];

				if (online && online.aid) return true;
				return false;
			},
			online() {
				let online = this.$store.getters['online/getOnline'];

				if (online && online.aid){
					if (this.keys[this.key]) {
						this.val = online.user[this.key];
					}
					
					return online;
				}
				return {};
			}
		},
		data() {
			return {
				key: '',
				val: '',
				keys: {
					name: '昵称',
					intro: '签名',
				}
			}
		},
		onLoad(props) {
			if (props.name) {
				this.key = props.name;
			}
		},
	
		methods: {
			clickAset() {
				if (!this.val || !this.key) {
					return this.$tip.show('请填写内容', 'warn');
				}
				
				let post = {} ;
				post[this.key] = this.val ; 
				let that = this;
				this.$loading.show('提交中');
				that.$iapi.vapi('my/upd', post, { 
					succ: js => {
						//刷新online
						that.$tip.show('修改成功', 'succ');
						setTimeout(function() {
							that.$online.fetch(function(){
								that.$go.back();
							});
						}, 1000);
					},
					ever: js => {
						this.$loading.hide();
					}
				});
			}
		}
	}
</script>

<style>
	page {
		background: #f5f5f5;
	}

	.msinput {
		display: flex;
		width: 694upx;
		height: 77upx;
		margin: 28upx auto;
		padding: 0 15upx;
		font-size: 28upx;
		line-height: 73upx;
		color: #838383;
		border: 1px solid #ccc;
		border-radius: 6upx;
		background: #fff;
		box-sizing: border-box;
	}

	.msinput input {
		display: block;
		height: 70upx;
		flex: 1;
		font-size: 28upx;
		line-height: 70upx;
		color: #333;
	}

	.submit {
		width: 300upx;
		height: 70upx;
		margin: 40upx auto 0;
		font-size: 28upx;
		line-height: 70upx;
		text-align: center;
		color: #fff;
		background: #ff7042;
		border-radius: 6upx;
	}
</style>
